package com.treeman.user.service;

import java.util.List;
import java.util.Set;

import org.springframework.security.access.prepost.PreAuthorize;

import com.treeman.api.json.user.UserJson;
import com.treeman.api.json.user.UserLocationJson;
import com.treeman.api.security.exception.InvalidUsernameOrPasswordException;
import com.treeman.friend.Invitation;
import com.treeman.friend.exception.InvitationAlreadyExistsException;
import com.treeman.friend.exception.InvitationNotFoundException;
import com.treeman.user.User;
import com.treeman.user.exception.UserExistsException;
import com.treeman.user.exception.UserNotFoundException;

public interface UserService extends
		org.springframework.security.core.userdetails.UserDetailsService {

	public void registerUser(User user) throws UserExistsException;

	public void login(User user);

	public User getUserByUsername(String username) throws UserNotFoundException;

	public UserJson getUserJsonByUsername(String username)
			throws UserNotFoundException;

	public User authenticateUser(String username, String password)
			throws InvalidUsernameOrPasswordException;

	public List<User> findUsers(String firstname, String lastName,
			String username);

	public UserLocationJson getUserLocationJson(String username,
			String requesterUsername) throws UserNotFoundException;

	public Set<User> getUserFriends(String username);

	@PreAuthorize("hasRole('ROLE_USER')")
	public void inviteFriend(String username, String friendUsername)
			throws UserNotFoundException, InvitationAlreadyExistsException;

	@PreAuthorize("hasRole('ROLE_USER')")
	public Set<Invitation> getRecievedInvitations(String username);

	@PreAuthorize("hasRole('ROLE_USER')")
	public void acceptInvitationFromUser(String acceptingUsername,
			String requestingUsername) throws InvitationNotFoundException;

	@PreAuthorize("hasRole('ROLE_USER')")
	public void rejectInvitationFromUser(String rejectingUsername,
			String requestingUsername) throws InvitationNotFoundException;

	public void changeUserPassword(String username, String newPassword,
			String oldPassword) throws InvalidUsernameOrPasswordException;
}